<?php

namespace Crontab\Model;

use Think\Model;


class GoodsSpecModel extends Model
{
    //排查库存、价格、以及香港库的价格不得超过5000
    public function troubleshootingStock($goods_list){
        $storestock = M("storestock");
        $stock_num = 0;
        $price_num = 0;
        foreach($goods_list as $k=>$v){
            $result = $this->where(array('goods_id'=>$v['goods_id']))->select();
            if(!empty($result)){
                //库存为0的情况
                foreach($result as $key=>$item) {
                    if ($item['stock'] > 0 && $item['price'] > 0) {
                        $stock_num += 1;
                        break;
                    } else {
                        $stock_num = 0;
                    }
                }
                //仓库为香港库国外直邮价格不得超过5000
                foreach($result as $qqq=>$aaa){
                    $storeInfo = $storestock->where(array('storestock_id'=>$aaa['spec_3value']))->find();
                    if($storeInfo && $storeInfo['stock_style'] == 2){
                        if($aaa['price'] > 5000){
                            $price_num += 1;
                            break;
                        }else{
                            $price_num = 0;
                        }
                    }
                }
                if($stock_num == 0 || $price_num >= 1){
                    unset($goods_list[$k]);
                }

            }else{
                unset($goods_list[$k]);
            }

        }
        return $goods_list;

    }
}